package cn.itcast.web.servlet;

import cn.itcast.domain.ChangeList;
import cn.itcast.service.ChangeListService;
import cn.itcast.service.impl.ChangeListServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findChangeListByStateIdServlet")
public class FindChangeListByStateIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置中文编码
        request.setCharacterEncoding("utf-8");
        //获取参数
        String uid = request.getParameter("uid");
        String uname = request.getParameter("uname");
        //1调用service方法
        ChangeListService service=new ChangeListServiceImpl();
        List<ChangeList> changelists=service.findAllByStateId();
        //2将list存入request域中,还有uid
        request.setAttribute("changelists",changelists);
        request.setAttribute("uid",uid);
        request.setAttribute("uname",uname);
        //3转发到ChangeListlista.jsp
        request.getRequestDispatcher("/ChangeListlista.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
